﻿Chenxin.UI.AchievementCollect = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/logic/AchievementCollect.ashx',
    createSearch: function() {
        return new Chenxin.UI.AchievementCollectSearch({
            scope: this
        });
    },
    createGrid: function() {
        return new Chenxin.UI.GroupReportGrid({
            actionUrl: this.actionUrl + '?op=getlist',
            id: 'search_table',
            renderTo: 'search_table',
            hasCheckBox: false,
            modelId: 'pointdepartid',
            cellBorder: true,
            height: 400,
            autoLoad: false,
            scope: this,
            rowGroupSetting: [
				{ field: 'business', head: '商圈', width: 120, autoCount: false },
				{ field: 'departname', head: '门店', width: 120, autoCount: false }
			],
            columns: {
                a: {
                    head: '佣金收付款（包括收入和支出）',
                    items: {
                        amoney: {
                            head: '买卖',
                            width: 120,
                            sortable: true,
							renderer:function(val,c,row){
								return '<a class="a_pay_details" type="10" title="'+val+'" style="cursor:pointer">'+val+'</a>';
							}
                        },
                        bmoney: {
                            head: '租赁',
                            width: 80,
                            sortable: true,
							renderer:function(val,c,row){
								return '<a class="a_pay_details" type="20" title="'+val+'" style="cursor:pointer">'+val+'</a>';
							}
                        },
                        cmoney: {
                            head: '零散',
                            width: 80,
                            sortable: true,
							renderer:function(val,c,row){
								return '<a class="a_pay_details" type="30" title="'+val+'" style="cursor:pointer">'+val+'</a>';
							}
                        },
                        dmoney: {
                            head: '其他',
                            width: 80,
                            sortable: true,
							renderer:function(val,c,row){
								return '<a class="a_pay_details" type="40" title="'+val+'" style="cursor:pointer">'+val+'</a>';
							}
                        },
                        allmoney: {
                            head: '合计',
                            width: 80,
                            sortable: true,
							renderer:function(val,c,row){
								return '<a class="a_pay_details" type="50" title="'+val+'" style="cursor:pointer">'+val+'</a>';
							}
                        }
                    }
                },
                b: {
                    head: '佣金收款（不包括支出）',
                    items: {
                        a_money: {
                            head: '买卖',
                            width: 120,
                            sortable: true,
							renderer:function(val,c,row){
								return '<a class="a_details" type="10" title="'+val+'" style="cursor:pointer">'+val+'</a>';
							}
                        },
                        b_money: {
                            head: '租赁',
                            width: 80,
                            sortable: true,
							renderer:function(val,c,row){
								return '<a class="a_details" type="20" title="'+val+'" style="cursor:pointer">'+val+'</a>';
							}
                        },
                        c_money: {
                            head: '零散',
                            width: 80,
                            sortable: true,
							renderer:function(val,c,row){
								return '<a class="a_details" type="30" title="'+val+'" style="cursor:pointer">'+val+'</a>';
							}
                        },
                        d_money: {
                            head: '其他',
                            width: 80,
                            sortable: true,
							renderer:function(val,c,row){
								return '<a class="a_details" type="40" title="'+val+'" style="cursor:pointer">'+val+'</a>';
							}
                        },
                        all_money: {
                            head: '合计',
                            width: 80,
                            sortable: true,
							renderer:function(val,c,row){
								return '<a class="a_details" type="50" title="'+val+'" style="cursor:pointer">'+val+'</a>';
							}
                        }
                    }
                }
            }
        });
    },
	showDetails:function(op,type,record){
		if(!this.detailsWin){
			this.detailsWin=new Chenxin.UI.DetailsWin({
				id:'x_details_win',
				actionUrl:this.actionUrl
			});
		}
		this.detailsWin.show();
		var title='『'+record.business+'/'+record.departname+'』';
		switch(type){
			case 10:
				title+='买卖';
				break;
			case 20:
				title+='租赁';
				break;
			case 30:
				title+='零散';
				break;
			case 40:
				title+='其他';
				break;
			case 50:
				title+='合计';
				break;
		}
		title+='详情';
		
		this.detailsWin.setTitle(title);
		this.detailsWin.grid.baseParam.op=op;
		this.detailsWin.grid.param.type=type;
		this.detailsWin.grid.param.pointdepartid=record.pointdepartid;
		Chenxin.apply(this.detailsWin.grid.param,this.search.getParamJson());
		this.detailsWin.grid.reload();
	},
    initEvent: function() {
        var _this = this;
    },
    initComponent: function() {
        Chenxin.UI.AchievementCollect.superclass.initComponent.call(this);
        this.searchGrid();
    }
});

Chenxin.UI.DetailsWin = Chenxin.extend(Chenxin.UI.Win, {
    id: '',
    actionUrl: '',
    width: 680,
    hasFoot: true,
    height: 360,
    content: '<div id="x_details_grid"></div>',
    createBtn: function() {
        return [{
            text: '关闭',
            handler: this.hide
}]
        },
        createGrid: function() {
            if (this.grid) {
                return;
            }
            this.grid = new Chenxin.UI.ReportGrid({
                baseParam: { op: '' },
                autoLoad: false,
                actionUrl: this.actionUrl,
                id: 'x_details_grid',
                renderTo: 'x_details_grid',
                hasCheckBox: false,
                cellBorder: true,
                modelId: 'a',
                scope: this,
                height: 311,
                hasTitle: false,
                columns: {
                    business: { head: '商圈', width: 100, sortable: true, captionCol: true },
                    departname: { head: '门店', width: 100, sortable: true, inTotal: false },
                    ContractCode: { head: '成交编号', width: 130, sortable: true, inTotal: false },
                    ContractDate: { head: '成交日期', width: 100, sortable: true, inTotal: false },
                    HouseAddress: { head: '房屋地址', width: 300, sortable: true, inTotal: false },
                    Point: { head: '点数', width: 100, sortable: true },
                    RealCommisionFinal: { head: '应收佣收', width: 100, sortable: true },
                    CommisionFinal: { head: '折佣', width: 100, sortable: true },
                    ConsultingFinal: { head: '咨询费', width: 100, sortable: true },
                    PayMoney: { head: '实收金额', width: 100, sortable: true,
                        renderer: function(val, c, row) {
                            if (row.InOrOut == '1')
                                return val;
                            else if (row.InOrOut == '-1')
                                return '-' + val;
                            else
                                return val;
                        }
                    },
                    ApportionPay: { head: '分摊实收金额', width: 100, sortable: true,
                        renderer: function(val, c, row) {
                            if (row.InOrOut == '1')
                                return val;
                            else if (row.InOrOut == '-1')
                                return '-' + val;
                            else
                                return val;
                        }
                    },
                    ApportionConsultingFinal: { head: '分摊咨询费', width: 100, sortable: true },
                    BusinessType: { head: '业务类型', width: 100, sortable: true, inTotal: false,
                        renderer: function(val, c, row) {
                            switch (val) {
                                case 10:
                                    return '买卖';
                                    break;
                                case 20:
                                    return '租赁';
                                    break;
                                case 30:
                                    return '零散';
                                    break;
                                case 40:
                                    return '其他';
                                    break;
                                default:
                                    return '';
                                    break;
                            }
                        }
                    }
                }
            });
        },
        initComponent: function() {
            Chenxin.UI.DetailsWin.superclass.initComponent.call(this);
            this.createGrid();
        }
    });

/**
*查询面板
*/
    Chenxin.UI.AchievementCollectSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
        id: 'search',
        initEvent: function() {
            var _this = this;

            //查询按钮
            $('#btn_search').click(function() {
                _this.scope.reloadGrid();
            });

            /*************************事件：起始日期得到焦点************************/
            $("#DateFr").focus(function() {
                WdatePicker({
                    dateFmt: 'yyyy-MM',
                    oncleared: function() {
                        $(this).blur();
                    },
                    onpicked: function() {
                        $(this).blur();
                    }
                });
            });
            var curdate = new Date();
            $('#DateFr').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 1));

            $('.a_pay_details').live('click', function() {
                _this.scope.showDetails('getpaydetails', $(this).attr('type'), _this.scope.grid.store.rows[_this.scope.grid.store.map[this.parentNode.parentNode.id].index]);
            });
            $('.a_details').live('click', function() {
            _this.scope.showDetails('getnopaydetails', $(this).attr('type'), _this.scope.grid.store.rows[_this.scope.grid.store.map[this.parentNode.parentNode.id].index]);
            });
        },
        createComboList: function() {
            var combl = new Chenxin.UI.StructComboList({
                tbxWidth: 65
            });

            //合同归属（城市）
            var comboBargainCityId = new Chenxin.UI.StructCombo({
                param: { op: 'getcity' },
                containerId: '#BargainCityId',
                name: 'BargainCityId',
                tbxWidth: 65,
                inModelType: 'all',
                txtModelName: 'BargainCityName',
                onSelected: function() {
                    if (this.getValue() == this.defVal) {
                        comboBargainCompanyId.clearItems();
                    } else {
                        comboBargainCompanyId.param.fatherid = this.getValue();
                        comboBargainCompanyId.reload();
                    }
                }
            });
            //合同归属（公司）
            var comboBargainCompanyId = new Chenxin.UI.StructCombo({
                param: { op: 'getcompany' },
                containerId: '#BargainCompanyId',
                name: 'BargainCompanyId',
                inModelType: 'all',
                tbxWidth: 65,
                autoLoad: false
            });


            //签约（城市）
            var comboGCityId = new Chenxin.UI.StructCombo({
                param: { op: 'getcity' },
                containerId: '#g_city',
                name: 'GCityId',
                tbxWidth: 65,
                inModelType: 'all',
                txtModelName: 'GCityName',
                onSelected: function() {
                    if (this.getValue() == this.defVal) {
                        comboGCompanyId.clearItems();
                        comboGBargainId.clearItems();
                    } else {
                        comboGCompanyId.param.fatherid = this.getValue();
                        comboGCompanyId.reload();
                    }
                }
            });
            //签约（公司）
            var comboGCompanyId = new Chenxin.UI.StructCombo({
                param: { op: 'getcompany' },
                containerId: '#g_company',
                name: 'GCompanyId',
                tbxWidth: 65,
                inModelType: 'all',
                txtModelName: 'GCompanyName',
                autoLoad: false,
                onSelected: function() {
                    if (this.getValue() == this.defVal) {
                        comboGBargainId.clearItems();
                    } else {
                        comboGBargainId.param.fatherid = this.getValue();
                        comboGBargainId.reload();
                    }
                }
            });
            //签约点
            var comboGBargainId = new Chenxin.UI.StructCombo({
                param: { op: 'getbargaindeparts' },
                containerId: '#g_bargain',
                name: 'GBargainId',
                inModelType: 'all',
                tbxWidth: 85,
                colWidth: 85,
                autoLoad: false
            });

            var structs = combl.comboList;
            structs.push(comboBargainCompanyId);
            structs.push(comboGBargainId);
            return structs;
        },
        initComponent: function() {
            Chenxin.UI.AchievementCollectSearch.superclass.initComponent.call(this);
        }
    });

getcity = true; //设置需要获取城市下拉框数据

$(document).ready(function() {
    var AchievementCollect = new Chenxin.UI.AchievementCollect();
});